<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="班级" prop="classId">
          <el-select v-model="queryParams.classId" clearable placeholder="请选择班级"
              filterable
              remote
              reserve-keyword
              :remote-method="remoteClass">
            <el-option
              v-for="item in classList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
              size="small">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="财务审核" prop="cwcCheck">
        <el-select v-model="queryParams.cwcCheck" placeholder="请选择财务审核状态" clearable size="small">
          <el-option
            v-for="dict in checkOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学生处" prop="xscCheck">
        <el-select v-model="queryParams.xscCheck" placeholder="请选择学生处审核状态" clearable size="small">
          <el-option
            v-for="dict in checkOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
        <el-form-item label="学生姓名" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入学生姓名"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleCheck1"
          v-hasPermi="['student:graduation:check']"
        >批量通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="error"
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleCheck2"
          v-hasPermi="['student:graduation:check']"
        >批量不通过</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="graduationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="年级" align="center" prop="year" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="学号" align="center" prop="code" />
      <el-table-column label="班级" align="center" prop="className" />
      <el-table-column label="专业" align="center" prop="specName" />

      <el-table-column label="财务审核" align="center">
        <el-table-column label="状态" align="center" prop="cwcCheck" :formatter="cwcCheckFormat" />
        <el-table-column label="姓名" align="center" prop="cwcName" />
        <el-table-column label="时间" align="center" prop="cwcTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.cwcTime) }}</span>
          </template>
        </el-table-column>
      </el-table-column>

      <el-table-column label="学生处审核" align="center">
        <el-table-column label="状态" align="center" prop="xscCheck" :formatter="xscCheckFormat" />
        <el-table-column label="姓名" align="center" prop="xscName" />
        <el-table-column label="时间" align="center" prop="xscTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.xscTime) }}</span>
          </template>
        </el-table-column>
      </el-table-column>

      <el-table-column label="班主任审核" align="center">
        <el-table-column label="状态" align="center" prop="bzrCheck" :formatter="bzrCheckFormat" />
        <el-table-column label="姓名" align="center" prop="bzrName" />
        <el-table-column label="时间" align="center" prop="bzrTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.bzrTime) }}</span>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog  :close-on-click-modal="false" :title="title" :visible.sync="open" width="600px" append-to-body>
      <student-archive :studentId="form.studentId"></student-archive>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { selectClazz } from "@/api/base/clazz";
import { listMasterGraduation, getGraduation, delGraduation, checkGraduation, updateGraduation, gradStudent } from "@/api/student/graduation";
import  StudentArchive  from '@/views/student/component/Archive';

export default {
  name: "GraduationFinance",
  components:{ StudentArchive },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 班级数据
      classList: [],
      // 毕业管理表格数据
      graduationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 班审核状态字典
      checkOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        classId: null,
        bzrCheck: '1',
        cwcCheck: null,
        xscCheck: null
      },
      form: {studentId:null}
    };
  },
  created() {
    this.getList();
    this.getDicts("check_status").then(response => {
      this.checkOptions = response.data;
    });
  },
  methods: {
    /** 查询毕业管理列表 */
    getList() {
      this.loading = true;
      listMasterGraduation(this.queryParams).then(response => {
        this.graduationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    remoteClass(query) {
      if (query !== '') {
          this.loading = true;
          selectClazz({title:query}).then(response => {
            this.classList = response.rows;
            this.total = response.total;
            this.loading = false;
          });
      } else {
         this.loading = true;
         selectClazz({status:'1'}).then(response => {
           this.classList = response.rows;
           this.total = response.total;
           this.loading = false;
         });
      }
    },
    // 班审核状态字典翻译
    bzrCheckFormat(row, column) {
      return this.selectDictLabel(this.checkOptions, row.bzrCheck);
    },
    // 财务审核状态字典翻译
    cwcCheckFormat(row, column) {
      return this.selectDictLabel(this.checkOptions, row.cwcCheck);
    },
    // 学生处审核状态字典翻译
    xscCheckFormat(row, column) {
      return this.selectDictLabel(this.checkOptions, row.xscCheck);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 批量通过按钮操作 */
    handleCheck1(row) {
      const id = row.id || this.ids
      this.handleUpdate(id, '1');
    },
    /** 批量不通过按钮操作 */
    handleCheck2(row) {
      const id = row.id || this.ids
      this.handleUpdate(id, '2');
    },
    /** 修改按钮操作 */
    handleUpdate(id, status) {
      var data = {cwcCheck:status,batchs:id};
      checkGraduation(data).then(response => {
        this.msgSuccess("操作成功");
        this.getList();
      });
    },
    handleView(row) {
      this.form.studentId = row.stuId;
      this.open = true;
      this.title = "学生档案";
    },
    cancel() {
      this.open = false;
    }
  }
};
</script>
